package cn.marinda.gui.impl;

import cn.marinda.gui.AbstractServerDialog;
import cn.marinda.listener.CloseCurrentDialogEvent;
import cn.marinda.util.HttpUtils;

import javax.swing.*;
import java.awt.*;
import java.util.List;

/**
 * 作者信息对话框
 *
 * @author admin
 * @date 2022/07/28
 */
public class GroupInfoDialog extends AbstractServerDialog {

    public static GroupInfoDialog instance = new GroupInfoDialog();
    /**
     * 没有找到核心服务器对话框
     */
    private GroupInfoDialog(){
        super();
    }

    @Override
    protected JDialog loadDialog() {
        dialog = new JDialog();
        dialog.setSize(400,720);
        dialog.setTitle("反馈信息");
        dialog.setLocationRelativeTo(null);
        dialog.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
        dialog.setResizable(false);
        dialog.setContentPane(view);
        return dialog;
    }

    @Override
    protected JPanel loadView() {
        view = new JPanel();
        Box box = Box.createVerticalBox();
        componentList.stream().forEach(ele->{
            box.add(ele);
            box.add(Box.createVerticalStrut(20));
        });
        view.add(box);
        return view;
    }

    @Override
    protected List<JComponent> loadComponent() {
        JLabel textMessage = new JLabel("加入群聊快速讨论！");
        textMessage.setForeground(Color.RED);
//        String path = System.getProperty("user.dir")+"/image/group.png";
        ImageIcon imageIcon = new ImageIcon(HttpUtils.loadAuthorInfo("group"));
        imageIcon.setImage(imageIcon.getImage().getScaledInstance(300,550,Image.SCALE_DEFAULT));
        JLabel portrait = new JLabel(imageIcon);
        JLabel qq = new JLabel("群号: 608535372");
        qq.setForeground(Color.RED);
        textMessage.setFont(new Font(null,Font.PLAIN,14));
        textMessage.setForeground(Color.black);
        JButton successBtn = new JButton("关闭");
        successBtn.setBorderPainted(false);
        successBtn.setFocusPainted(false);
        successBtn.setBackground(Color.RED);
        successBtn.setForeground(Color.black);
        successBtn.addActionListener(new CloseCurrentDialogEvent(this));
        componentList.add(textMessage);
        componentList.add(portrait);
        componentList.add(qq);
        componentList.add(successBtn);
        return componentList;
    }

    @Override
    public void open() {
        dialog.setVisible(true);
    }

    @Override
    public void close() {
        dialog.setVisible(false);
    }
}
